package com.sskj.gocoin.mine;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.TextView;

import com.sskj.common.base.App;
import com.sskj.gocoin.ComDialog;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.mine.data.BenefitBean;
import com.sskj.gocoin.mine.data.TuiguangBean;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.NumberUtil;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

public class BenefitActivity extends BaseActivity<BenefitPresenter> {
    @BindView(R2.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R2.id.btn_benefit_invite)
    Button inviteBtn;
    @BindView(R2.id.btn_benefit_hb)
    Button hbBtn;
    @BindView(R2.id.tv_benefit_ljfy_name2)
    TextView name2Tv;
    @BindView(R2.id.tv_benefit_ljfy_name1)
    TextView tvBenefitLjfyName1;
    @BindView(R2.id.tv_benefit_ljfy_name3)
    TextView tvBenefitLjfyName3;
    @BindView(R2.id.tv_benefit_ljfy2)
    TextView tvBenefitLjfy2;
    @BindView(R2.id.tv_benefit_ljfy1)
    TextView tvBenefitLjfy1;
    @BindView(R2.id.tv_benefit_ljfy3)
    TextView tvBenefitLjfy3;
    @BindView(R2.id.tv_benefit_grade)
    TextView tvBenefitGrade;
    @BindView(R2.id.tv_benefit_money)
    TextView tvBenefitMoney;
    @BindView(R2.id.tv_benefit_detail)
    TextView tvBenefitDetail;
//    @BindView(R2.id.tv_benefit_gz)
//    TextView tvBenefitGz;
//    @BindView(R2.id.tv_benefit_yh_1)
//    TextView tvBenefitYh1;
//    @BindView(R2.id.tv_benefit_gz_1)
//    TextView tvBenefitGz1;
//    @BindView(R2.id.tv_benefit_yh_2)
//    TextView tvBenefitYh2;
//    @BindView(R2.id.tv_benefit_gz_2)
//    TextView tvBenefitGz2;
//    @BindView(R2.id.tv_benefit_yh_3)
//    TextView tvBenefitYh3;
//    @BindView(R2.id.tv_benefit_gz_3)
//    TextView tvBenefitGz3;

    private TuiguangBean tuiguangBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_benefit;
    }

    @Override
    public BenefitPresenter getPresenter() {
        return new BenefitPresenter();
    }

    @Override
    protected void initView() {
        toolbar.setLeftButtonOnClickLinster(v -> finish());

        ClickUtil.click(inviteBtn, () -> {
            mPresenter.getTuiGuang();
        });
        ClickUtil.click(hbBtn, () -> {
            HBActivity.start(this);
//            startActivity(new Intent(this, HBActivity.class));
        });
        ClickUtil.click(tvBenefitDetail,()->{
            startActivity(new Intent(this,MoneyDetailActivity.class));
        });
    }

    @Override
    protected void initData() {
        mPresenter.getBenefit();
    }

    public void onGetBenefit(BenefitBean benefitBean) {
        if (benefitBean != null) {
            tvBenefitGrade.setText(benefitBean.getGrade()+","+benefitBean.getRate()+"%");
//            tvBenefitGz.setText(benefitBean.getFygz());
            tvBenefitMoney.setText(TextUtils.isEmpty(benefitBean.getMoney())? "0" : NumberUtil.keep2(benefitBean.getMoney())+ "USDT");
//            tvBenefitYh1.setText(benefitBean.getLvs().getFree_rate1()+"%");
//            tvBenefitYh2.setText(benefitBean.getLvs().getFree_rate2()+"%");
//            tvBenefitYh3.setText(benefitBean.getLvs().getFree_rate3()+"%");
//            tvBenefitGz1.setText(App.INSTANCE.getString(R.string.wyhl_dtqy) +benefitBean.getLvs().getLv1()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
//            tvBenefitGz2.setText(App.INSTANCE.getString(R.string.wyhl_dtqy)+benefitBean.getLvs().getLv2()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
//            tvBenefitGz3.setText(App.INSTANCE.getString(R.string.wyhl_dtqy)+benefitBean.getLvs().getLv3()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
            List<BenefitBean.PaimingBean> paiming = benefitBean.getPaiming();
            if (paiming != null && !paiming.isEmpty()) {
                tvBenefitLjfyName1.setText(paiming.get(0).getName());
                tvBenefitLjfy1.setText(NumberUtil.keep2(paiming.get(0).getMoney()) +" USDT");
                if (paiming.size()>=2){
                    name2Tv.setText(paiming.get(1).getName());
                    tvBenefitLjfy2.setText(NumberUtil.keep2(paiming.get(1).getMoney())+" USDT");
                }
                if(paiming.size()>=3){
                    tvBenefitLjfyName3.setText(paiming.get(2).getName());
                    tvBenefitLjfy3.setText(NumberUtil.keep2(paiming.get(2).getMoney())+" USDT");
                }
            }
        }
    }

    public void onGetTuiguang(TuiguangBean tuiguangBean){
        this.tuiguangBean = tuiguangBean;
        ComDialog comDialog = new ComDialog(this, App.INSTANCE.getString(R.string.wyhl_fz), App.INSTANCE.getString(R.string.xmlbottom_sheet_selector22), App.INSTANCE.getString(R.string.wyhl_fzcontent)+"\n" +
                tuiguangBean.getUrl(), new ComDialog.OnComBtnClickListener() {
            @Override
            public void onConfirm() {
                //获取剪贴板管理器：
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                // 创建普通字符型ClipData
                ClipData mClipData = ClipData.newPlainText("wx", tuiguangBean.getUrl());
                // 将ClipData内容放到系统剪贴板里。
                cm.setPrimaryClip(mClipData);
                ToastUtil.showShort("已复制到粘贴板");
            }

            @Override
            public void onCancel() {

            }
        });
        comDialog.show();
    }
}
